local extension = Package:new("tea_ex_cards", Package.CardPack)
extension.extensionName = "wild_collection"
Fk:loadTranslationTable{
  ["tea_ex_cards"] = "茶水额外牌堆",
}

local slash = Fk:cloneCard("slash")
local shotSlashSkill = fk.CreateActiveSkill{
    name = "tea_shot__slash_skill",
    max_phase_use_time = 1,
    target_num = 1,
    can_use = slash.skill.canUse,
    mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
      local player = Fk:currentRoom():getPlayerById(to_select)
      local from = Fk:currentRoom():getPlayerById(user)
      return from ~= player
    end,
    target_filter = function(self, to_select, selected, _, card, extra_data)
      local count_distances = not (extra_data and extra_data.bypass_distances)
      if #selected < self:getMaxTargetNum(Self, card) then
        local player = Fk:currentRoom():getPlayerById(to_select)
        return self:modTargetFilter(to_select, selected, Self.id, card, count_distances) and
        (
          #selected > 0 or
          Self.phase ~= Player.Play or
          (extra_data and extra_data.bypass_times) or
          self:withinTimesLimit(Self, Player.HistoryPhase, card, "slash", player)
        )
      end
    end,
    on_effect = function(self, room, effect)
      local to = effect.to
      local from = effect.from
      room:damage({
        from = room:getPlayerById(from),
        to = room:getPlayerById(to),
        card = effect.card,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name
      })
    end
}
local shotSlash = fk.CreateBasicCard{
  name = "&tea_shot__slash",
  skill = shotSlashSkill,
  is_damage_card = true,
  suit = Card.Heart,
  number = 13,
}
extension:addCard(shotSlash)
Fk:loadTranslationTable{
  ["tea_shot__slash_skill"] = "射杀",
  ["tea_shot__slash"] = "射杀",
  [":tea_shot__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：一名其他角色<br /><b>效果</b>：对目标角色造成1点伤害。<br/>",
}

local teaSkill = fk.CreateActiveSkill{
  name = "tea__analeptic_skill",
  prompt = "#tea__analeptic_skill",
  max_target_num = 1,
  max_phase_use_time = 1,
  mod_target_filter = function(self, to_select, _, _, card, _)
    return not table.find(Fk:currentRoom().alive_players, function(p)
      return p.dying
    end)
  end,
  target_filter = function(self, to_select, selected, _, card, extra_data)
    if #selected < self:getMaxTargetNum(Self, card) then
      local player = Fk:currentRoom():getPlayerById(to_select)
      return self:modTargetFilter(to_select, selected, Self.id, card) and
      (
        #selected > 0 or
        Self.phase ~= Player.Play or
        (extra_data and extra_data.bypass_times) or
        self:withinTimesLimit(Self, Player.HistoryPhase, card, "tea__analeptic", player)
      )
    end
  end,
  can_use = function(self, player, card, extra_data)
    return not player:isProhibited(player, card) and ((extra_data and (extra_data.bypass_times or extra_data.analepticRecover)) or
      self:withinTimesLimit(player, Player.HistoryTurn, card, "tea__analeptic", player))
  end,
  on_use = function(_, _, use)
    if not use.tos or #TargetGroup:getRealTargets(use.tos) == 0 then
      use.tos = { { use.from } }
    end

    if use.extra_data and use.extra_data.analepticRecover then
      use.extraUse = true
    end
  end,
  on_effect = function(_, room, effect)
    local to = room:getPlayerById(effect.to)
    if effect.extra_data and effect.extra_data.analepticRecover then
      room:recover({
        who = to,
        num = 1,
        recoverBy = room:getPlayerById(effect.from),
        card = effect.card,
      })
    else
      room:addPlayerMark(to, MarkEnum.AddMaxCardsInTurn, 1)
      to:reset()
    end
  end
}

local tea = fk.CreateBasicCard{
  name = "&tea__analeptic",
  skill = teaSkill,
  suit = Card.Spade,
  number = 3,
}
extension:addCards{
  tea,
  tea:clone(Card.Club, 3),
  tea:clone(Card.Heart, 3),
  tea:clone(Card.Diamond, 3),
}
Fk:loadTranslationTable{
  ["tea__analeptic_skill"] = "茶",
  ["tea__analeptic"] = "茶",
  [":tea__analeptic"] = "基本牌<br/><b>时机</b>：①出牌阶段；②你濒死时<br/><b>目标</b>：①包括你在内的一名角色；②你。<br /><b>效果</b>：①复原目标武将牌，本回合其手牌上限+1；②目标角色回复1点体力。<br/>",
  ["#tea__analeptic_skill"] = "使用【茶】",
}

return extension